package com.jcfk.eam.controller.mould;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.eam.domain.dto.mould.ProjectMouldDTO;
import com.jcfk.eam.domain.query.mould.ProjectMouldQuery;
import com.jcfk.eam.service.mould.EamMouldProjectMouldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 通用产品模具关系表
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-11-13
 */
@Api(tags = {"通用产品模具关系表管理"})
@RestController
@RequestMapping("eammodprojectmould")
public class MouldProjectMouldController {
    @Autowired
    private EamMouldProjectMouldService eamMouldProjectMouldService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamModProjectMouldQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询通用产品模具关系表")
    @PostMapping("/queryByPage")
    public RetPage<ProjectMouldDTO> queryByPage(@RequestBody ReqPageParam<ProjectMouldQuery> requestParam) {
        DataPage<ProjectMouldDTO> page = new DataPage<ProjectMouldDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            ProjectMouldDTO.class);
        page = eamMouldProjectMouldService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  通用产品模具关系表
     * 根据id 查询详情
     */
    @ApiOperation("查询通用产品模具关系表")
    @GetMapping("/get/{id}")
    public RetResult<ProjectMouldDTO> get(@PathVariable("id") String id) {
            ProjectMouldDTO item = eamMouldProjectMouldService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理通用产品模具关系表
     */
    @ApiOperation("保存通用产品模具关系表")
    @PostMapping("/save")
    @RequestLogHeader(modular = "通用产品模具关系表管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid ProjectMouldDTO eamModProjectMould) {
        // 数据校验
        RetResult ret = eamMouldProjectMouldService.isValid(eamModProjectMould);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamModProjectMould.getId())){
            // 新增
            eamMouldProjectMouldService.insert(eamModProjectMould);
        } else{
            // 更新
            eamMouldProjectMouldService.update(eamModProjectMould);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除通用产品模具关系表
     */
    @ApiOperation("批量删除通用产品模具关系表")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "通用产品模具关系表管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody ProjectMouldDTO eamModProjectMould) {
        return RetResult.ok(eamMouldProjectMouldService.logicDeleteList(eamModProjectMould));
    }





    /**
     *  删除通用产品模具关系表
     */
    @ApiOperation("删除通用产品模具关系表")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "通用产品模具关系表管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamMouldProjectMouldService.deleteItem(id);
        return RetResult.ok();
    }
}
